<template>
  <div class="patient-group">
    <header class="header">
      <h1>默认分组</h1>
      <input
        type="text"
        v-model="searchQuery"
        placeholder="请输入患者相关信息"
        class="search-input"
      />
    </header>
    <ul class="patient-list">
      <li
        v-for="patient in patients" :key="patient.patientRecordId" class="patient-item">
        <div class="patient-info" @click="selectDetailByPatient(patient)">
          <span>{{ patient.patientName }}</span>
          <span>{{ patient.patientSex }}</span>
          <span>{{ patient.patientAge }}岁</span>
          <span>添加时间{{ patient.createTime }}</span>
        </div>
        <button class="consult-button">专家问诊</button>
      </li>
    </ul>
    <div v-if="!patients.length" class="no-more">
      没有更多了~
    </div>

      <!-- 模态框背景及内容 -->
      <div v-if="selectedPatient" class="modal-mask" @click.self="selectedPatient = null">
        <div class="modal-container">
          <div class="modal-header">
            <h2>{{ selectedPatient.patientName }} 的详细信息</h2>
          </div>
          <div class="modal-body">
            <p>性别: {{ selectedPatient.patientSex }}</p>
            <p>年龄: {{ selectedPatient.patientAge }}</p>
            <p>电话: {{ selectedPatient.patientTel }}</p>
            <p>就诊描述: {{ selectedPatient.patientDesc }}</p>
          </div>
          <div class="modal-footer">
            <button @click="selectedPatient = null">关闭</button>
          </div>
        </div>
      </div>

  </div>
</template>

<script>
import {getPatientList} from "@/api/doctor/patient/patient";
import Modal from "@/plugins/modal";


export default {
  components: {
    Modal // 这里注册了 Modal 组件，这样就可以在模板中以 <modal> 标签的形式使用它了。
  },

  data() {
    return {
      selectedPatient: null, // 当前选中的患者详情
      searchQuery: '',
      patients: [],
    };
  },

  methods: {
    //查询分组内患者详情
    showPatientDetails(groupId) {
      getPatientList(groupId).then(res => {
        if (res.code !== 500) {
          this.patients = res.data;
        } else {
          this.$message.error(res.msg);
        }
      })
    },
    //查询患者详情
    selectDetailByPatient(patient) {
      this.selectedPatient = patient;
    },
  },
  created() {
    // 获取参数
    const groupId = this.$route.params.groupId
    // 这里可以继续处理参数
    console.log('接收到的组ID:', groupId)
    this.showPatientDetails(groupId) // 示例：调用获取数据的方法
  }
};
</script>

<style scoped>
.patient-group {
  padding: 20px;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.search-input {
  padding: 5px;
  border: 1px solid #ccc;
  border-radius: 4px;
}

.patient-list {
  list-style: none;
  padding: 0;
}

.patient-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px;
  border-bottom: 1px solid #eee;
  cursor: pointer;
}

.patient-info span {
  margin-right: 10px;
}

.consult-button {
  background-color: #ffcc00;
  border: none;
  padding: 5px 10px;
  border-radius: 4px;
  cursor: pointer;
}

.no-more {
  text-align: center;
  margin-top: 20px;
  color: #999;
}
/* 简单的模态框样式 */
.modal-mask {
  position: fixed;
  z-index: 9998;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, .5);
  display: table;
  transition: opacity .3s ease;
}

.modal-container {
  max-width: 500px;
  margin: 150px auto;
  padding: 20px 30px;
  background-color: #fff;
  border-radius: 2px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .33);
  transition: all .3s ease;
  font-family: Helvetica, Arial, sans-serif;
}

.modal-header {
  margin-top: 0;
  color: #42b983;
}

.modal-body {
  margin: 20px 0;
}

.modal-footer button {
  background-color: #42b983;
  color: white;
  border: none;
  border-radius: 3px;
  padding: 10px;
  cursor: pointer;
}

.modal-footer button:hover {
  background-color: #3a9e76;
}
</style>
